package cn.pfz.controller;

import cn.pfz.Service.ISystemDictionarySerives;
import cn.pfz.domain.JsonResult;
import cn.pfz.domain.SystemDictionary;
import cn.pfz.query.QueryObject;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionarySerives systemDictionarySerives;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo) {

        Subject subject = SecurityUtils.getSubject();
        if(subject.isPermitted("systemDictionary:list")){
            PageInfo<SystemDictionary> list = systemDictionarySerives.list(qo);
            model.addAttribute("result",list);
            return "systemDictionary/list";
        }
        return "redirect:/erro/nopermission";

    }


    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(SystemDictionary department){
        if(department.getId()!=null){
            //修改
            systemDictionarySerives.updateByPrimaryKey(department);
        }else{
            systemDictionarySerives.insert(department);
        }
        return "redirect:/systemDictionary/list";
    }


    @ResponseBody
    @RequestMapping ("/delete")
    public JsonResult delete(Long id){
        systemDictionarySerives.deleteByPrimaryKey(id);
        return JsonResult.success(null);
    }
}
